package com.rxst.msg.server.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rxst.msg.dto.search.MsgxEquipmentSearchDto;
import com.rxst.msg.entity.MsgxEquipmentEntity;
import com.rxst.msg.mapper.MsgxEquipmentMapper;
import com.rxst.msg.server.MsgxEquipmentService;
import com.rxst.msg.sso.entity.UserContext;
import com.rxst.msg.vo.MsgxEquipmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 设备授权表
 *
 * @author rxst
 * @email rxst@gmail.com
 * @date 2021-08-19 11:47:00
 */
@Service("msgxEquipmentService")
@Transactional(rollbackFor = Exception.class)
public class MsgxEquipmentServiceImpl extends ServiceImpl<MsgxEquipmentMapper, MsgxEquipmentEntity> implements MsgxEquipmentService {

    @Autowired
    private MsgxEquipmentMapper mapper;

    @Override
    public List<MsgxEquipmentVo> list(MsgxEquipmentSearchDto vo) {
        return mapper.list(vo);
    }

    @Override
    public PageInfo<MsgxEquipmentVo> page(MsgxEquipmentSearchDto vo) {
        PageHelper.startPage(vo.getCurrent(), vo.getSize());
        PageInfo<MsgxEquipmentVo> page = new PageInfo<>(mapper.list(vo));
        return page;
    }

    @Override
    public Boolean saveEntity(MsgxEquipmentEntity t) {
        t.setEquipmentId(IdUtil.fastSimpleUUID());
        UserContext context = UserContext.getUserContext();
        if(context != null){
            t.setCreateBy(context.getCurrentUserId());
            t.setUpdateBy(context.getCurrentUserId());
        }
        return save(t);
    }

    @Override
    public Boolean saveEntityBatch(List<MsgxEquipmentEntity> list) {
        if (CollUtil.isNotEmpty(list)) {
            for (MsgxEquipmentEntity entity : list) {
                //todo
            }
            return saveBatch(list);
        }
        return false;
    }

    @Override
    public Boolean updateEntity(MsgxEquipmentEntity t) {
        UserContext context = UserContext.getUserContext();
        if(context != null){
            t.setCreateBy(context.getCurrentUserId());
        }
        return updateById(t);
    }

    @Override
    public Boolean updateEntityBatch(List<MsgxEquipmentEntity> list) {
        if (CollUtil.isNotEmpty(list)) {
            for (MsgxEquipmentEntity entity : list) {
                //todo
            }
            return updateBatchById(list);
        }
        return false;
    }

    @Override
    public void deleteLogic(Long id) {
        mapper.deleteLogic(id);
    }

    @Override
    public void deleteLogicByIds(List<Long> ids) {
        mapper.deleteLogicByIds(ids);
    }

}

